package shiyan32;
import java.util.HashSet;
import java.util.Set;

public class SetExample {
    public static void main(String[] args) {
        // 创建HashSet存储字符串
        Set<String> stringSet = new HashSet<>();
        
        // 添加一些字符串(包含重复项)
        String[] stringsToAdd = {"apple", "banana", "apple", "orange", "banana", "orange"};
        System.out.println("初始集合大小: " + stringSet.size());
        for (String str : stringsToAdd) {
            boolean added = stringSet.add(str);
            System.out.println("添加 '" + str + "': " + (added ? "成功" : "失败(重复)"));
        }
        System.out.println("最终集合大小: " + stringSet.size());
        System.out.println("集合内容: " + stringSet);
        
        // 通过大小变化判断是否有重复
        if (stringsToAdd.length > stringSet.size()) {
            System.out.println("检测到有重复元素被自动去重");
        } else {
            System.out.println("没有重复元素");
        }
    }
}
